package org.halk;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 映射 /welcome 路径的 POST 请求
 * @Author haozhu7
 * @Date 2025/11/18 11:06
 **/
@WebServlet("/welcome")
public class WelcomeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 设置响应编码（防止中文乱码）
        response.setContentType("text/plain;charset=UTF-8");

        // 获取当前时间（格式化）
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = sdf.format(new Date());

        // 构建响应内容
        String welcomeMsg = "欢迎使用本服务！当前时间：" + currentTime;

        // 输出响应
        try (PrintWriter out = response.getWriter()) {
            out.println(welcomeMsg);
        }
    }
}